package main
import (
    "fmt"
	"sync"
)

type UserAges struct {
	ages map[string]int
	sync.RWMutex
}

func (ua *UserAges) Init(){
	ua.ages = make(map[string]int)

}

func (ua *UserAges) Add(name string, age int) {
	ua.Lock()
	defer ua.Unlock()
	ua.ages[name] = age
}

func (ua *UserAges) Get(name string) int {
	ua.RLock()
	defer ua.RUnlock()

	if age, ok := ua.ages[name]; ok {
		return age
	}
	return -1
}


func main() {
	var userAge UserAges;
	userAge.Init()
	userAge.Add("foo", 1)
	

	fmt.Printf("value=%v\n", userAge.Get("foo"))

	var iTmp int
	fmt.Printf("iTmp=%v\n", iTmp)
}


 

	

 